﻿<%@ WebHandler Language="C#" Class="submit_ajax" %>

using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.SessionState;
//using fcwms.Web.UI;
using fcwms.Common;

public class submit_ajax : IHttpHandler, IRequiresSessionState
{
    public void ProcessRequest(HttpContext context)
    {
        //取得处事类型
        string action = DTRequest.GetQueryString("action");

        switch (action)
        {
            //case "sys_channel_load": //加载频道管理菜单
            //    sys_channel_load(context);
            //    break;
            //case "plugins_nav_load": //加载插件管理菜单
            //    plugins_nav_load(context);
            //    break;

            case "validate_user_id": //验证用户编号是否重复
                validate_user_id(context);
                break;
            case "validate_role_name": //验证角色名称是否重复
                validate_role_name(context);
                break;
            case "validate_decla_id": //验证报关单号是否重复
                validate_decla_id(context);
                break;
            case "validate_kuwei": //验证报关单号是否重复
                validate_kuwei(context);
                break;
        }

    }
     #region 验证库位是否可用==============================
    private void validate_kuwei(HttpContext context)
    {
        string position = DTRequest.GetFormString("position");

        //如果为Null，退出
        if (string.IsNullOrEmpty(position))
        {
            context.Response.Write("false");
            return;
        }
        fcwms.BLL.dt_location bll = new fcwms.BLL.dt_location();
        //查询数据库
        if (bll.Exists(position.Trim()))
        {
            context.Response.Write("false");
            return;
        }
        context.Response.Write("true");
        return;
    }
     #endregion

    #region 验证用户编号是否可用==============================
    private void validate_user_id(HttpContext context)
    {
        string user_id = DTRequest.GetFormString("user_id");

        //如果为Null，退出
        if (string.IsNullOrEmpty(user_id))
        {
            context.Response.Write("false");
            return;
        }
        fcwms.BLL.dt_users bll = new fcwms.BLL.dt_users();
        //查询数据库
        if (bll.Exists(user_id.Trim()))
        {
            context.Response.Write("false");
            return;
        }
        context.Response.Write("true");
        return;
    }
    #endregion

    #region 验证角色名称是否可用==============================
    private void validate_role_name(HttpContext context)
    {
        string role_name = DTRequest.GetFormString("role_name");
        string oldrole_name = DTRequest.GetFormString("oldrole_name");

        //如果为Null，退出
        if (string.IsNullOrEmpty(role_name))
        {
            context.Response.Write("false");
            return;
        }
        //检查是否修改操作
        if (role_name == oldrole_name)
        {
            context.Response.Write("true");
            return;
        }
        fcwms.BLL.dt_role bll = new fcwms.BLL.dt_role();
        //查询数据库
        if (bll.Exists(role_name.Trim()))
        {
            context.Response.Write("false");
            return;
        }
        context.Response.Write("true");
        return;
    }
    #endregion
    
    #region 验证报关单号是否可用==============================
    private void validate_decla_id(HttpContext context)
    {
        string decla_id = DTRequest.GetFormString("decla_id");
        string olddecla_id = DTRequest.GetFormString("olddecla_id");
        //如果为Null，退出
        if (string.IsNullOrEmpty(decla_id))
        {
            context.Response.Write("false");
            return;
        }
        //检查是否修改操作
        if (decla_id == olddecla_id)
        {
            context.Response.Write("true");
            return;
        }
       fcwms.BLL.dt_ruku bll = new fcwms.BLL.dt_ruku();
        //查询数据库
        if (bll.Exists(decla_id.Trim()))
        {
            context.Response.Write("false");
            return;
        }
        context.Response.Write("true");
        return;
    }
    #endregion
 
    public bool IsReusable
    {
        get
        {
            return false;
        }
    } 
   
}